//
//  YYMDetailsListCell.m
//  On The Load
//
//  Created by 我爱的妞 on 15/11/15.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "YYMDetailsListCell.h"
#import "YMDetailsListModel.h"
#import <UIImageView+WebCache.h>

@implementation YYMDetailsListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createSubViews];
    }
    
    return self;
}

- (void)createSubViews{
    
    _stars = [NSMutableArray array];
    
    _mainImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 205)];
    _mainImgView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:_mainImgView];
    
    // 初始化Label
    _titleLabel = [[UILabel alloc] init];
    // 设置x，y，width，height
    _titleLabel.frame = CGRectMake(20, 215, WIDTH - 150, 25);
    // 设置背景颜色
    _titleLabel.textColor = [UIColor blackColor];
    _titleLabel.font = [UIFont systemFontOfSize:15.5];
    
    [self.contentView addSubview:_titleLabel];
    
    _ditanceLabel = [[UILabel alloc] init];
    // 设置x，y，width，height
    _ditanceLabel.frame = CGRectMake(WIDTH - 120, 215, 120, 25);
    // 设置背景颜色
    _ditanceLabel.textColor = [UIColor grayColor];
    _ditanceLabel.font = [UIFont systemFontOfSize:14.5];
    
    [self.contentView addSubview:_ditanceLabel];
    
    // 初始化Label
    _tagLabel = [[UILabel alloc] init];
    // 设置x，y，width，height
    _tagLabel.frame = CGRectMake(20, 245, WIDTH - 40, 25);
    // 设置背景颜色
    _tagLabel.textColor = [UIColor grayColor];
    _tagLabel.font = [UIFont systemFontOfSize:14.5];
    
    [self.contentView addSubview:_tagLabel];
    
    for (int i = 0; i < 5; i++) {
        
        UIImageView *starView = [[UIImageView alloc] initWithFrame:CGRectMake(20 + 25 * i, 280, 14, 14)];
        
        [self.contentView addSubview:starView];
        [_stars addObject:starView];
    }
    
    // 初始化Label
    _ratingLabel = [[UILabel alloc] init];
    // 设置x，y，width，height
    _ratingLabel.frame = CGRectMake(150, 274, WIDTH - 250, 25);
    // 设置背景颜色
    _ratingLabel.textColor = [UIColor grayColor];
    _ratingLabel.font = [UIFont systemFontOfSize:14.5];
    
    [self.contentView addSubview:_ratingLabel];
    
    _desLabel = [[UILabel alloc] init];
    // 设置x，y，width，height
    _desLabel.frame = CGRectMake(20, 310, WIDTH - 40, 50);
    // 设置背景颜色
    _desLabel.textColor = [UIColor grayColor];
    _desLabel.font = [UIFont systemFontOfSize:14.5];
    _desLabel.numberOfLines = 0;
    
    [self.contentView addSubview:_desLabel];
}

- (void)setModel:(YMDetailsListModel *)model{
    
    _model = model;
    
    [_mainImgView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:nil];
    
    _titleLabel.text = model.name;
    _ditanceLabel.text = @"50km以上";
    _tagLabel.text = model.foodtype;
    
    CGFloat score = [model.score floatValue];
    
    
    for (int i = 1; i < 6; i++) {
        
        UIImageView *imgV = [_stars objectAtIndex:i - 1];
        
        if (score >= i) {
            imgV.image = [UIImage imageNamed:@"iconfont-shoucang-@2x"];
        }else{
            imgV.image = [UIImage imageNamed:@"iconfont-shoucang@2x"];
        }
        
    }
    
    _ratingLabel.text = [NSString stringWithFormat:@"%@人评论", model.commentnum];
    _desLabel.text = model.impression;
}

@end
